//
//  SinaTabBarViewController.swift
//  weibo
//
//  Created by guyue on 15/12/30.
//  Copyright © 2015年 guyue. All rights reserved.
//

import UIKit

class SinaTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
                
        //添加子控制器
        addChildViewController()
        
        //改变系统的tabBar
        
        let tabbar = SinaTabBar()
        
        //系统的tabBar是只读的属性,不能直接赋值,需要用KVC来赋值. KVC可以给只读属性赋值
        
        //tabBar = tabbar
        
        
        setValue(tabbar, forKeyPath: "tabBar")
        
        //发布按钮的点击事件
        tabbar.composeButton.addTarget(self, action: "publish", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    //MKRK:---发布按钮点击要实现的方法
    
    func  publish(){
    
        printLog("发布界面")
    
    }
    
    //添加子控制器的封装
    func addChildViewController() {
        
        addChildViewController(SinaHomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(SinaMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(SinaFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(SinaSettingViewController(), title: "设置", image: "tabbar_profile")

    }
    
    //MARK: 抽象封装添加子控制器的方法--重载
    func addChildViewController(childController: UIViewController,title:String,image:String) {
        //设置标题
        childController.title = title
        
        //设置图片
        childController.tabBarItem.image = UIImage(named: image)
        //选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        //设置nav
        let nav = UINavigationController(rootViewController: childController)
        
        //添加控制器
        addChildViewController(nav)
        
    }
    
    
    
    
    

    }
